{* Модуль задач *}

<script type="text/javascript">
<!--{literal}
$(document).ready
(
    function()
    {
	$('input:checkbox#tasks-only-my').click
	(
	    function()
	    {
		$.getJSON
		(
		    'json/taskFilter.php',
		    { 'only_my': ($(this).attr('checked')?1:0) },
		    function(json)
		    {
			if ( json['code']==200 ) { window.location.reload(); }
		    }
		);
	    }
	);
    }
);
{/literal}-->
</script>

{* Подключение Диалоговых окон для работы с задачами *}
{include file="admin/submodules/task.dialog.html"}

<!-- НАЧАЛО блока задач -->
<table class="ui-widget ui-state-default" width="100%" cellspacing="0">
    <thead class="ui-widget-header">
	<tr>
	    <th colspan="7">Задачи</th>
	</tr>
	<tr>
	    <th>#</th>
	    <th>Создана</th>
	    <th>Постановщик</th>
	    {if $smarty.session.manager.is_admin==1 && $smarty.session.filter.tasks.only_my!=1}<th>Ответственный</th>{/if}
	    <th>Клиент</th>
	    <th>Осталось</th>
	    <th>Задача</th>
	</tr>
    </thead>
    <tbody>
    {foreach from=$tasks item=task name=tasks}
	<tr class="task-row {if $task.before<-60}ui-state-error{elseif $task.before<10}ui-state-highlight{else}ui-state-default{/if}">
	    <td align="right"><span style="display: none;">{$task.id}</span>{$smarty.foreach.tasks.iteration}</td>
	    <td align="center">{$task.date_time|date_format:'%d.%m.%Y, %H:%M'}</td>
	    <td align="center">{$task.c_manager}</td>
	    {if $smarty.session.manager.is_admin==1}<td>{$task.r_manager}</td>{/if}
	    <td align="center"><a href="customer-view.php?id={$task.customer_id}">{$task.customer_name|sslash}</a></td>
	    <td align="center">
	    {if $task.before==''}
	    &mdash;
	    {elseif $task.before|abs<60}
		{$task.before} мин.
	    {elseif $task.before|abs<1440}
		{math equation=x/60 x=$task.before assign=hours format=%d}
		{math equation=x%60 x=$task.before assign=mins format=%d}
		{$hours} ч.{if $mins!=0}, {$mins|abs} мин.{/if}
	    {else}
		{math equation=x/1440 x=$task.before assign=days format=%d}
		{math equation=x%1440/60 x=$task.before assign=hours days=$days format=%d}
		{math equation=x%1440%60 x=$task.before assign=mins format=%d}
		{$days} д.{if $hours!=0}, {$hours|abs} ч.{/if}{if $mins!=0}, {$mins|abs} мин.{/if}
	    {/if}
	    </td>
	    <td><a href="task.php?id={$task.id}">{$task.note}</a></td>
	</tr>
    {foreachelse}
	<tr><td colspan="7" align="center" class="ui-state-default"><i>нет задач</i></td></tr>
    {/foreach}
    </tbody>
    {if $smarty.session.manager.is_admin==1}
    <tfoot>
	<tr>
	    <td colspan="7" align="right">
		<input type="checkbox" id="tasks-only-my" {if $smarty.session.filter.tasks.only_my==1}checked{/if}/>
		<label for="tasks-only-my">только мои задачи</label>
	    </td>
	</tr>
    </tfoot>
    {/if}
</table>
<!-- КОНЕЦ блока задач -->
